from Crypto.Cipher import DES
from Crypto.Util.Padding import pad
import base64

IV_64_JK = bytes([0, 0, 0, 0, 0, 0, 0, 0])

def encode_des(data, key):
    if not data:
        return data
    
    try:
        des = DES.new(key.encode('utf-8'), DES.MODE_CBC, IV_64_JK)
        padded_data = pad(data.encode('utf-8'), DES.block_size)
        encrypted_data = des.encrypt(padded_data)
        ret = base64.b64encode(encrypted_data).decode('utf-8')
        return ret
    except Exception as e:
        print(f"Encryption error: {e}")
        return ""

